package com.rm.zeyou.controller;

import cn.dev33.satoken.annotation.SaCheckLogin;
import com.github.pagehelper.PageInfo;
import com.rm.zeyou.entity.User;
import com.rm.zeyou.response.ApiRestResponse;
import com.rm.zeyou.service.UserCouponService;
import com.rm.zeyou.util.login.LoginUtil;
import com.rm.zeyou.vo.request.SelectOrderCanUseCouponListVo;
import com.rm.zeyou.vo.request.SelectUserCouponListVo;
import com.rm.zeyou.vo.request.UserReceiveCouponVo;
import com.rm.zeyou.vo.request.UserReceiveLimitCouponVo;
import com.rm.zeyou.vo.response.SelectUserCouponListResponseVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

/**
 * <p>
 * 用户优惠卷 前端控制器
 * </p>
 *
 * @author YanYang
 * @since 2025-03-12 15:55:09
 */
@Api(tags = "用户优惠券相关")
@RestController
@RequestMapping("/api/userCoupon")
public class UserCouponController {
    @Resource
    private UserCouponService userCouponService;
    @Resource
    private LoginUtil loginUtil;

    @PostMapping("selectUserCouponList")
    @ApiOperation("查询用户优惠券列表")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<PageInfo<SelectUserCouponListResponseVo>> selectUserCouponList(@RequestBody SelectUserCouponListVo requestVo) {
        User user = loginUtil.getUser();
        return userCouponService.selectUserCouponList(user.getId(),requestVo);
    }

    @PostMapping("userReceiveCoupon")
    @ApiOperation("用户领取优惠券")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<Integer> userReceiveCoupon(@RequestBody UserReceiveCouponVo receiveCouponVo) {
        User user = loginUtil.getUser();
        return userCouponService.userReceiveCoupon(user.getId(), receiveCouponVo);

    }


    @PostMapping("userReceiveLimitCoupon")
    @ApiOperation("用户领取限时优惠券")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<Integer> userReceiveLimitCoupon(@RequestBody UserReceiveLimitCouponVo receiveCouponVo) {
        User user = loginUtil.getUser();
        return userCouponService.userReceiveLimitCoupon(user.getId(), receiveCouponVo);

    }


    @ApiOperation("查询订单可用优惠券列表")
    @PostMapping("selectOrderCanUseCouponList")
    @SaCheckLogin(type = "user")
    public ApiRestResponse<PageInfo<SelectUserCouponListResponseVo>> selectOrderCanUseCouponList(@RequestBody SelectOrderCanUseCouponListVo canUseCouponListVo) {
        User user = loginUtil.getUser();
        return userCouponService.selectOrderCanUseCouponList(user.getId(), canUseCouponListVo);

    }


}
